<template>
  <div style="display: flex">
    <div class="trees_box1">
      <el-tree
        :data="Treedata"
        accordion
        :props="defaultProps"
        highlight-current
        @node-click="handleNodeClick"
      >
      </el-tree>
    </div>
    <div class="app-container" style="width: 85%">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="100px"
      >
        <el-form-item label="小题名称" prop="smallTopic">
          <el-input
            v-model="queryParams.smallTopic"
            placeholder="请输入小题名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="题目类型" prop="type">
        <el-input
          disabled
          v-model="queryParams.type"
          placeholder="请输入小题名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="所属题库" prop="bankTypeId">
          <el-select
            v-model="queryParams.bankTypeId"
            filterable
            allow-create
            default-first-option
            placeholder="请选择所属题库"
            clearable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in questionBankType"
              :key="index"
              :label="item.name"
              :value="item.id"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="填空数量" prop="optionCount">
        <el-input
          v-model="queryParams.optionCount"
          placeholder="请输入填空数量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
        <!--      <el-form-item label="答案(选择题/判断题可能会有)" prop="answer">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.answer"-->
        <!--          placeholder="请输入答案(选择题/判断题可能会有)"-->
        <!--          clearable-->
        <!--          size="small"-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <el-form-item label="分数" prop="fraction">
          <el-input
            v-model="queryParams.fraction"
            placeholder="请输入分数"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="一级知识点" prop="knowledgeA">
          <el-input
            v-model="queryParams.knowledgeA"
            placeholder="请输入一级知识点"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="二级知识点" prop="knowledgeB">
          <el-input
            v-model="queryParams.knowledgeB"
            placeholder="请输入二级知识点"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="考察知识点" prop="investigateKnow">
          <el-input
            v-model="queryParams.investigateKnow"
            placeholder="请输入考察知识点"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="认知分类" prop="categorization">
          <el-input
            v-model="queryParams.categorization"
            placeholder="请输入认知分类"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="难易程度" prop="difficulty">
          <el-select
            v-model="queryParams.difficulty"
            filterable
            allow-create
            default-first-option
            placeholder="请选择难易程度"
            clearable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in field103Options"
              :key="index"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容相关性" prop="correlation">
          <el-input
            v-model="queryParams.correlation"
            placeholder="请输入内容相关性"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="模板分类" prop="formwork">
          <el-select
            v-model="queryParams.formwork"
            @change="handleFormwork()"
            default-first-option
            placeholder="请选择模板"
            clearable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in formworkOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            clearable
            size="small"
            v-model="queryParams.createTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createBy">
          <el-input
            v-model="queryParams.createBy"
            placeholder="请输入创建人"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            >修改</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            >删除</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="questionbankList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="创建人" align="center" prop="id" />-->
        <!-- <el-table-column label="大题名称" align="center" prop="bigQuestion" /> -->
        <el-table-column
          label="小题名称"
          :show-overflow-tooltip="true"
          width="160"
          prop="smallTopic"
        >
        <template slot-scope="scope">
            <div class="html_box ql-editor">
              <div v-html="scope.row.smallTopic"></div>
            </div>
          </template>
        </el-table-column>

        <el-table-column label="题目类型" align="center" prop="type" />
        <!-- <el-table-column label="选项数量" align="center" prop="optionCount" /> -->
        <el-table-column
          label="答案"
          :show-overflow-tooltip="true"
          align="center"
          prop="answer"
        />
        <el-table-column label="分数" align="center" prop="fraction" />
        <el-table-column
          label="一级知识点"
          :show-overflow-tooltip="true"
          align="center"
          prop="knowledgeA"
        />
        <el-table-column
          label="二级知识点"
          :show-overflow-tooltip="true"
          align="center"
          prop="knowledgeB"
        />
        <el-table-column
          label="考察知识点"
          :show-overflow-tooltip="true"
          align="center"
          prop="investigateKnow"
        />
        <el-table-column
          label="认知分类"
          :show-overflow-tooltip="true"
          align="center"
          prop="categorization"
        />
        <el-table-column label="难易程度" align="center" prop="difficulty" />
        <el-table-column
          label="内容相关性"
          :show-overflow-tooltip="true"
          align="center"
          prop="correlation"
        />
        <el-table-column
          label="模板分类"
          :show-overflow-tooltip="true"
          align="center"
          prop="formwork"
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" prop="createBy" />
        <el-table-column
          label="修改时间"
          align="center"
          prop="updateTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="修改人" align="center" prop="updateBy" />
        <el-table-column
          label="操作"
          align="center"
          width="180px"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleShow(scope.row)"
              v-hasPermi="['topic:moreselect:show']"
              >预览</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['topic:questionbank:edit']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['topic:questionbank:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 预览 -->
      <el-dialog
        :visible.sync="Showdetail"
        width="40%"
        v-if="Showdetail"
        append-to-body
      >
        <div>
          <showDetail :row="propdata"></showDetail>
        </div>
      </el-dialog>
      <!-- 添加或修改基本题库管理对话框 -->
      <!-- 尝试移植为dialog -->
      <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
        <el-row :gutter="15">
          <el-form
            ref="elForm"
            :model="formData"
            :rules="dialogrules"
            size="medium"
            label-width="100px"
            label-position="left"
          >
            <el-col :span="12">
              <el-form-item label="题目类型" prop="type">
                <el-input
                  v-model="formData.type"
                  placeholder="请输入题目类型"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="所属题库" prop="bankTypeId">
                <el-select
                  v-model="formData.bankTypeId"
                  default-first-option
                  placeholder="请选择模板"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in questionBankType"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24"></el-col>
            <el-col :span="12">
              <el-form-item label="难易程度" prop="difficulty">
                <el-select
                  v-model="formData.difficulty"
                  placeholder="请选择难易程度"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in field103Options"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="模板分类" prop="formwork">
                <el-select
                  v-model="formData.formwork"
                  @change="handleFormwork()"
                  default-first-option
                  placeholder="请选择模板"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in formworkOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24"></el-col>
            <el-col :span="12">
              <el-form-item label="分值" prop="fraction">
                <el-input
                  v-model.trim="formData.fraction"
                  placeholder="请输入分值"
                  clearable
                  disabled
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="简答题名称" prop="smallTopic">
                <!-- <el-input
                  v-model="formData.smallTopic"
                  type="textarea"
                  placeholder="请输入小题名称"
                  :autosize="{ minRows: 4, maxRows: 4 }"
                  :style="{ width: '100%' }"
                ></el-input> -->
                <Editor style="width: 580px" v-model="formData.smallTopic"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <!-- <el-form-item label="上传" prop="img" required> 加上required就是必须要上传图片才能提交-->
              <!-- headers设置请求头 -->
              <el-form-item label="上传" prop="img">
                <el-upload
                  ref="img"
                  :file-list="imgList"
                  :action="field101Action"
                  list-type="picture"
                  :limit="9"
                  accept=".jpg, .png"
                  :headers="header"
                  :before-remove="beforeRemove"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :on-success="handleSucces"
                  :before-upload="field101BeforeUpload"
                >
                  <el-button size="small" type="primary" icon="el-icon-upload"
                    >图片上传</el-button
                  >
                </el-upload>
                <el-upload
                  ref="img"
                  :file-list="fileList"
                  :action="field101Action"
                  list-type="text"
                  :limit="9"
                  accept=".pdf, .doc, .docx, .xls, .xlsx"
                  :headers="header"
                  :before-remove="filebeforeRemove"
                  :on-preview="filehandlePreview"
                  :on-remove="filehandleRemove"
                  :on-success="filehandleSucces"
                  :before-upload="filefield101BeforeUpload"
                >
                  <el-button size="small" type="primary" icon="el-icon-upload"
                    >文件上传</el-button
                  >
                </el-upload>

                <el-upload
                  :file-list="audioList"
                  :action="field101Action"
                  list-type="text"
                  :limit="1"
                  accept=".wave,.aiff,.mpeg,.mp3,.midi,.wma,.amr,.ape,.flac,.acc"
                  :headers="header"
                  :before-remove="audioBeforeRemove"
                  :on-remove="audioFilehandleRemove"
                  :on-success="audioFilehandleSucces"
                >
                  <el-button size="small" type="primary" icon="el-icon-upload">
                    音频上传
                  </el-button>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="答案" prop="answer">
                <el-input
                  v-model="formData.answer"
                  type="textarea"
                  placeholder="请输入答案"
                  :autosize="{ minRows: 4, maxRows: 4 }"
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="小题讲解" prop="explains">
                <el-input
                  v-model="formData.explains"
                  type="textarea"
                  placeholder="请输入小题讲解"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="考察知识点" prop="investigateKnow">
                <el-input
                  v-model="formData.investigateKnow"
                  placeholder="请输入考察知识点"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="一级知识点" prop="knowledgeA">
                <el-input
                  v-model="formData.knowledgeA"
                  type="textarea"
                  placeholder="请输入一级知识点"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="二级知识点" prop="knowledgeB">
                <el-input
                  v-model="formData.knowledgeB"
                  type="textarea"
                  placeholder="请输入二级知识点"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="认知分类" prop="categorization">
                <el-input
                  v-model="formData.categorization"
                  placeholder="请输入认知分类"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="内容相关性" prop="correlation">
                <el-input
                  v-model="formData.correlation"
                  placeholder="请输入内容相关性"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item size="large" class="clearfix">
                <span class="right">
                  <el-button type="primary" @click="dialogsubmitForm"
                    >提交</el-button
                  >
                  <el-button @click="dailogresetForm">重置</el-button>
                </span>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {
  listQuestionbank,
  getQuestionbank,
  delQuestionbank,
  addQuestionbank,
  updateQuestionbank,
  exportQuestionbank,
  getQueryTree,
} from "@/api/topic/questionbank";
import {
  addMoreSelect,
  search,
  changeMoreSelect,
  getFormark,
  deleQuestion,
  deleQuestions,
} from "@/api/topic/moerselect";
import showDetail from "@/components/showDetail";
import { listTemplate } from "@/api/topic/template";
import { listQuestionBankType } from "@/api/topic/QuestionBankType";
export default {
  name: "moreselect",
  components: { showDetail: showDetail },
  data() {
    return {
      // 树数据
      Treedata: [],
      defaultProps: {
        children: "data",
        label: "courseName",
      },
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/upload",
        // 上传的文件列表
        fileList: [],
      },
      header: { Authorization: "Bearer " + getToken() },
      propdata: [],
      delkey: "",
      deleitemIndex: "",
      num: 1,
      myaddkey: 0,
      formData: {
        type: "简答题",
        beanName: "shortAnswerServiceImpl",
        explains: undefined,
        fraction: undefined,
        difficulty: undefined,
        smallTopic: undefined,
        optionCount: 0,
        bankTypeId: null,
        point: undefined,
        field106: undefined,
        investigateKnow: undefined,
        knowledgeA: undefined,
        knowledgeB: undefined,
        options: [],
        imgUrl: "",
        fileUrl: "",
      },
      field101Action: process.env.VUE_APP_BASE_API + "/common/upload",
      imgList: [],
      fileList: [],
      audioList:[],
      selectoptions: [],
      dialogrules: {
        bankTypeId: [
          {
            required: true,
            message: "请选择所属题库",
            trigger: "blur",
          },
        ],
        field108: [
          {
            required: true,
            type: "array",
            message: "请至少选择一个答案",
            trigger: "change",
          },
        ],
        formwork: [
          {
            required: true,
            message: "请输入或选择模板分类",
            trigger: "blur",
          },
        ],
        explains: [
          {
            required: true,
            message: "请输入小题讲解",
            trigger: "blur",
          },
        ],
        answer: [
          {
            required: true,
            message: "请输入答案",
            trigger: "blur",
          },
        ],
        difficulty: [
          {
            required: true,
            message: "选择题目难度",
            trigger: "blur",
          },
        ],
        type: [
          {
            required: true,
            message: "请输入题目类型",
            trigger: "blur",
          },
        ],
        fraction: [
          {
            required: true,
            message: "请输入分值,必须是数字",
            trigger: "blur",
          },
        ],
        field103: [
          {
            required: true,
            message: "请输入难易程度",
            trigger: "change",
          },
        ],
        smallTopic: [
          {
            required: true,
            message: "请输入小题名称",
            trigger: "blur",
          },
        ],
        field108: [
          {
            required: true,
            message: "选项不能为空",
            trigger: "change",
          },
        ],
        field110: [
          {
            required: true,
            message: "请输入考察知识点",
            trigger: "blur",
          },
        ],
        field111: [
          {
            required: true,
            message: "请输入一级知识点",
            trigger: "blur",
          },
        ],
        field112: [
          {
            required: true,
            message: "请输入二级知识点",
            trigger: "blur",
          },
        ],
        field113: [
          {
            required: true,
            message: "请输入认知分类",
            trigger: "blur",
          },
        ],
        field114: [
          {
            required: true,
            message: "请输入内容相关性",
            trigger: "blur",
          },
        ],
      },
      field103Options: [
        {
          label: "0.1",
          value: 0.1,
        },
        {
          label: "0.2",
          value: 0.2,
        },
        {
          label: "0.3",
          value: 0.3,
        },
        {
          label: "0.4",
          value: 0.4,
        },
        {
          label: "0.5",
          value: 0.5,
        },
        {
          label: "0.6",
          value: 0.6,
        },
        {
          label: "0.7",
          value: 0.7,
        },
        {
          label: "0.8",
          value: 0.8,
        },
        {
          label: "0.9",
          value: 0.9,
        },
        {
          label: "1",
          value: 1,
        },
      ],
      formworkOptions: [],
      options: ["true", "false"],
      //图片和文件的前缀
      exhead: "http://10.168.100.154" + process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 是否显示预览内容
      Showdetail: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 题库
      questionBankType: [],
      // 基本题库管理表格数据
      questionbankList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 题目类型字典
      typeOptions: [],
      // 认知分类字典
      categorizationOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bigQuestion: null,
        smallTopic: null,
        // type: "简答题",
        beanName: "shortAnswerServiceImpl",
        optionCount: null,
        answer: null,
        bankTypeId: null,
        fraction: null,
        knowledgeA: null,
        knowledgeB: null,
        investigateKnow: null,
        categorization: null,
        difficulty: null,
        correlation: null,
        formwork: null,
        createTime: null,
        createBy: null,
        courseId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getQueryTree();
    this.getFormarkdata();
    this.getDicts("question_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("topic_categorization").then((response) => {
      this.categorizationOptions = response.data;
    });
  },
  methods: {
    //提交模板类型
    handleFormwork() {
      //约束分数
      console.log("模板类型", this.formData.formwork);
      for (let i = 0; i < this.formworkOptions.length; i++) {
        if (this.formworkOptions[i].value == this.formData.formwork) {
          this.formData.fraction = this.formworkOptions[i].questionScore;
          this.formData.questionTemplateId = this.formworkOptions[i].id;
        }
      }
    },
    getQueryTree() {
      this.loading = true;
      getQueryTree().then((res) => {
        this.Treedata = res;
        this.loading = false;
      });
    },

    // 树形目录点击后获取对应的学生信息
    handleNodeClick(data) {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        bigQuestion: null,
        smallTopic: null,
        // type: "简答题",
        beanName: "shortAnswerServiceImpl",
        optionCount: null,
        answer: null,
        bankTypeId: null,
        fraction: null,
        knowledgeA: null,
        knowledgeB: null,
        investigateKnow: null,
        categorization: null,
        difficulty: null,
        correlation: null,
        formwork: null,
        createTime: null,
        createBy: null,
        courseId: null,
      };
      switch (data.flag) {
        case "startingUnit": // 一级
          break;
        case "course": // 二级
          // this.queryParams.courseId = data.id;
          break;
        case "bankType": // 三级
          this.queryParams.bankTypeId = data.id;
          break;
        default:
          break;
      }
      /** 查询课程信息列表 */
      this.getList();
    },

    //获取模板类型
    getFormarkdata() {
      this.loading = true;
      const data = {
        beanName: this.formData.beanName,
      };
      listTemplate(data).then((response) => {
        this.formworkOptions = response.rows;
        for (let i = 0; i < response.rows.length; i++) {
          this.formworkOptions[i].label = response.rows[i].name;
          this.formworkOptions[i].value = response.rows[i].name;
        }
        console.log("题型模板", this.formworkOptions);
      });
      // getFormark(data).then((response) => {
      //   for (let i = 0; i < response.length; i++) {
      //     this.formworkOptions[i] = {
      //       label: response[i],
      //       value: response[i],
      //     };
      //   }
      // });
    },
    //移除图片前事件
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    //上传图片成功
    handleSucces(response, file, fileList) {
      this.formData.imgUrl += response.fileName + ",";
      console.log(fileList);
    },
    //图片预览
    handlePreview(file) {},
    //移除图片
    handleRemove(file, fileList) {
      let imgtemplatedata = [];
      imgtemplatedata = this.formData.imgUrl.split(",");
      this.formData.imgUrl = "";
      for (let i = 0; i <= imgtemplatedata.length - 2; i++) {
        if (file.response.fileName == imgtemplatedata[i]) {
        } else {
          this.formData.imgUrl += imgtemplatedata[i] + ",";
        }
      }
    },
    //选择图片
    field101BeforeUpload(file) {},
    //移除图片前事件
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    //上传文件成功
    filehandleSucces(response, file, fileList) {
      this.formData.fileUrl += response.fileName + ",";
    },
    //文件预览
    filehandlePreview(file) {},
    //移除文件
    filehandleRemove(file, fileList) {
      let imgtemplatedata = [];
      imgtemplatedata = this.formData.fileUrl.split(",");
      this.formData.fileUrl = "";
      for (let i = 0; i <= imgtemplatedata.length; i++) {
        if (file.response.fileName == imgtemplatedata[i]) {
        } else {
          this.formData.fileUrl += imgtemplatedata[i] + ",";
        }
      }
    },
    // 移除音频文件
    audioFilehandleRemove(){
      this.formData.audioUrl = "";
    },

    //音频文件上传文件成功
    audioFilehandleSucces(response, file, fileList) {
      this.formData.audioUrl = response.fileName;
      console.log(this.fileList);
    },

    //选择文件
    filefield101BeforeUpload(file) {},
    //移除文件事件
    filebeforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    // 音频文件移除
    audioBeforeRemove(file, fileList){
      return this.$confirm(`确定移除音频文件 ${file.name}？`);
    },

    dialogsubmitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.formData.fraction = parseFloat(this.formData.fraction);
          if (this.formData.id != null) {
            console.log("修改简答题");
            changeMoreSelect(this.formData).then((response) => {
              this.msgSuccess("修改简答题成功");
              this.dailogresetForm();
              this.open = false;
              this.getList();
            });
          } else {
            console.log("新增简答题", this.formData);
            addMoreSelect(this.formData).then((response) => {
              this.msgSuccess("添加简答题成功");
              this.open = false;
              this.dailogresetForm();
              this.getList();
              this.getFormarkdata();
            });
          }
        }

        // TODO 提交表单
      });
    },
    dailogresetForm() {
      this.formData = {
        type: "简答题",
        beanName: "shortAnswerServiceImpl",
        explains: "",
        fraction: undefined,
        difficulty: undefined,
        smallTopic: undefined,
        optionCount: 0,
        point: "",
        bankTypeId: undefined,
        field106: undefined,
        investigateKnow: undefined,
        knowledgeA: undefined,
        knowledgeB: undefined,
        options: [],
        imgUrl: "",
        fileUrl: "",
      };
      this.fileList = [];
      this.imgList = [];
      this.options = [];
      this.selectoptions = [];
      (this.delkey = ""),
        (this.deleitemIndex = ""),
        (this.num = 1),
        (this.myaddkey = 0);
    },
    /** 查询基本题库管理列表 */
    getList() {
      this.loading = true;
      listQuestionbank(this.queryParams).then((response) => {
        this.questionbankList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listQuestionBankType().then((response) => {
        this.questionBankType = response.rows;
      });
    },
    // 题目类型字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 认知分类字典翻译
    categorizationFormat(row, column) {
      return this.selectDictLabel(
        this.categorizationOptions,
        row.categorization
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentId: null,
        personId: null,
        bigQuestion: null,
        smallTopic: null,
        type: null,
        optionCount: null,
        answer: null,
        fraction: null,
        knowledgeA: null,
        knowledgeB: null,
        investigateKnow: null,
        categorization: null,
        difficulty: null,
        correlation: null,
        formwork: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 预览按钮操作 */
    handleShow(row) {
      this.propdata = row;
      this.Showdetail = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.dailogresetForm();
      this.open = true;
      this.title = "添加简答题题库管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.dailogresetForm();
      //const id = row.id || this.ids;
      const data = {
        bankId: row.id || this.ids[0],
        beanName: "shortAnswerServiceImpl",
      };
      search(data).then((response) => {
        this.formData = response;
        this.imgList = [];
        this.fileList = [];
        let imgtemplatedata = [];
        let filetemplatedata = [];
        if (this.formData.fileUrl) {
          filetemplatedata = this.formData.fileUrl.split(",");
        }
        if (this.formData.imgUrl) {
          imgtemplatedata = this.formData.imgUrl.split(",");
        }
        const that = this;
        for (let i = 0; i <= imgtemplatedata.length - 2; i++) {
          const data = {
            uid: i,
            name: imgtemplatedata[i],
            url: this.exhead + imgtemplatedata[i],
            response: {
              fileName: imgtemplatedata[i],
            },
          };
          this.imgList[i] = data;
        }
        for (let i = 0; i <= filetemplatedata.length - 2; i++) {
          const data = {
            uid: i,
            url: this.exhead + filetemplatedata[i],
            name: filetemplatedata[i],
            response: {
              fileName: filetemplatedata[i],
            },
          };
          this.fileList[i] = data;
        }
        this.open = true;
        this.title = "修改简答题题库管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateQuestionbank(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuestionbank(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let data = {};
      if (typeof ids == "string") {
        data = {
          bankId: ids,
          beanName: this.formData.beanName,
        };
        this.$confirm(
          '是否确认删除简答题题库管理编号为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return deleQuestion(data);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => {});
      } else {
        data = {
          bankIds: ids,
          beanName: this.formData.beanName,
        };
        this.$confirm(
          '是否确认删除简答题题题题库管理编号为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return deleQuestions(data);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => {});
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有简答题题库管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportQuestionbank(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style>
.html_box{
  height: 55px;
}
.radio-answer {
  margin-left: 10px;
}
.radio-answer-point {
  margin-left: 5px;
  color: #909399;
}
.bank-radio {
  display: flex;
  flex-direction: column;
}
.radio-item {
  margin-top: 10px;
}
.icon {
  display: inline;
  margin-left: 20px;
}
.el-upload__tip {
  line-height: 1.2;
}
</style>


